#!/bin/bash
LNMP_Configuration(){
. ./var
#nginx配置
    [ -f /usr/local/nginx/conf/nginx.conf ] && mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak1
    if [ 0 = 0 ];then
        wget -O /usr/local/nginx/conf/nginx.conf https://download.gobgm.com/file/All_conf/nginx.conf.zabbix
#        wget -O /usr/local/nginx/html/index.php https://download.gobgm.com/file/All_conf/index.php
#"EOF"表示不引用变量。而EOF则要引用变量
cat > /usr/local/nginx/html/index.php << "EOF"
<?php
    $link_id=mysqli_connect('127.0.0.1','root','666666') or mysql_error();
    if($link_id) {
        echo "php link mysql successful";
    }else{
        echo mysql_error();
    }
phpinfo();
?>
EOF
    echoYellow "重载nginx"
        /usr/local/nginx/sbin/nginx -s reload
        ps aux |grep nginx
    
    echoGreen "nginx配置完成"
        sleep 6
    else
        echoRed "/usr/local/nginx/conf/nginx.conf备份失败"
    fi

#php配置
    if [ -f /usr/local/php/etc/php-fpm.d/www.conf ];then
        sed -i.bak "s/^user =.*/user = nginx/" /usr/local/php/etc/php-fpm.d/www.conf
        sed -i.bak "s/^group =.*/group = nginx/" /usr/local/php/etc/php-fpm.d/www.conf
        egrep "^user|^group" /usr/local/php/etc/php-fpm.d/www.conf
    else
        echoRed "/usr/local/php/etc/php-fpm.d/www.conf,该文件修改失败"
    fi
    
    if [ -f /usr/local/php/etc/php.ini ];then
        sed -i.bak "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /usr/local/php/etc/php.ini
        sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /usr/local/php/etc/php.ini
        sed -i "s#post_max_size = 8M#post_max_size = 16M#g" /usr/local/php/etc/php.ini
        sed -i "s#max_input_time = 60#max_input_time = 300#g" /usr/local/php/etc/php.ini
        sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /usr/local/php/etc/php.ini
        sed -i "s/;mbstring.func_overload = 0/mbstring.func_overload = 0\n/" /usr/local/php/etc/php.ini
        egrep "^date.timezone|^max_execution_time|^post_max_size|^max_input_time|^memory_limit|^mbstring.func_overload" /usr/local/php/etc/php.ini
    else
        echoRed "/usr/local/php/etc/php.ini,该文件修改失败"
    fi
    
    /etc/init.d/php-fpm restart
    echoGreen "php配置完成" 
    sleep 6  
#手动配置mysql
    echoYellow '数据库授权LNMP'
#    echoYellow "mysql -uroot -p666666 -e \"GRANT ALL PRIVILEGES ON *.* TO root@'localhost' identified by '666666';\""
    echoYellow "mysql -uroot -p666666 -e \"GRANT ALL PRIVILEGES ON *.* TO root@'127.0.0.1' identified by '666666';\""
    echoYellow "mysql -uroot -p666666 -e \"flush privileges;\""
}
